/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.erossi.pigest.web.iva;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.erossi.pigest.model.iva.AliquotaIva;
import org.springframework.web.servlet.view.document.AbstractExcelView;

/**
 * 'ListaAliquoteIvaHSSFView' class: classe che costituisce la vista per la versione HSSF
 *   della lista delle aliquote IVA.
 *
 * @author erossi
 * @version Sep 6, 2009
 */
public class ListaAliquoteIvaHSSFView extends AbstractExcelView {

  @Override
  @SuppressWarnings("unchecked")
  protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {

    HSSFSheet sheet_0 = workbook.createSheet(this.getApplicationContext().getMessage("bean.vat_rates", null, request.getLocale()));

    HSSFRow row_0 = sheet_0.createRow(0);

    HSSFCell cell_r0c0 = row_0.createCell((short) 0);
    cell_r0c0.setCellValue(this.getApplicationContext().getMessage("bean.vat_rates.id", null, request.getLocale()));
    HSSFCell cell_r0c1 = row_0.createCell((short) 1);
    cell_r0c1.setCellValue(this.getApplicationContext().getMessage("bean.vat_rates.version", null, request.getLocale()));
    HSSFCell cell_r0c2 = row_0.createCell((short) 2);
    cell_r0c2.setCellValue(this.getApplicationContext().getMessage("bean.vat_rates.description", null, request.getLocale()));
    HSSFCell cell_r0c3 = row_0.createCell((short) 3);
    cell_r0c3.setCellValue(this.getApplicationContext().getMessage("bean.vat_rates.rate", null, request.getLocale()));
    
    
    List<AliquotaIva> aliquoteIva = (List<AliquotaIva>) model.get("listaAliquoteIva");
    
    if (aliquoteIva != null) {
    
      for (int i = 0; i < aliquoteIva.size(); i++) {
        
        AliquotaIva aliquotaIva_i = aliquoteIva.get(i);
        
        HSSFRow row_i = sheet_0.createRow(i + 1);
        
        HSSFCell cell_rIc0 = row_i.createCell((short) 0);
        Long id = aliquotaIva_i.getId();
        if (id != null) {cell_rIc0.setCellValue(id);}
        
        HSSFCell cell_rIc1 = row_i.createCell((short) 1);
        Long version = aliquotaIva_i.getVersion();
        if (version != null) {cell_rIc1.setCellValue(version);}
        
        HSSFCell cell_rIc2 = row_i.createCell((short) 2);
        String descrizione = aliquotaIva_i.getDescrizione();
        if (descrizione != null) {cell_rIc2.setCellValue(descrizione);}

        HSSFCell cell_rIc3 = row_i.createCell((short) 3);
        Double aliquota = aliquotaIva_i.getAliquota();
        if (aliquota != null) {cell_rIc3.setCellValue(aliquota);}
        
      }
    
    }
    
  }
  
}

